<template>
	<view class="box">
		<image src="../../static/login/login.png" mode='aspectFit' class="logo"></image>
		<view class="title">LOGO区域</view>
		<view class="form">
		
			<!-- <input class="input" @input"username" placeholder-class placeholder="请输入用户名" />
			<input class="input" v-model="password" placeholder-class password placeholder="请输入密码"/>
			<button class="btn">立即登录</button>
		 -->
			
			<form @submit="formSubmit">
				<view>
				<input class="input" name="username" placeholder="用户名" />
				</view>
				<view>
				<input class="input" name="password" placeholder="密码" />
				</view>
				<view class="uni-btn-v">
					<button form-type="submit" class="btn">Submit</button>
					
				</view>
			</form>
		</view>
	</view>
</template>

<script>
import {decode,encode} from "../utils/codec.js"
  export default {
	        data() {
	            return {
	            }
	        },
	        methods: {
	            formSubmit: function(e) {
	                console.log('form发生了submit事件，携带数据为：' + JSON.stringify(e.detail.value))
	                var formdata = e.detail.value
					let requestPacket = {
					        username: formdata.username,
					        password: formdata.password,
					        version: 1,
					        command: 1
					    };
						
				uni.connectSocket({
				    url: 'ws://localhost:9999/chat',
				    data() {
				       
				    }
				});
			
				let cao = encode(requestPacket);
				 uni.sendSocketMessage({
				      data: cao
				    });
				uni.onSocketOpen(function (res) {
				  console.log('WebSocket连接已打开！');
				});
				uni.onSocketError(function (res) {
				  console.log('WebSocket连接打开失败，请检查！');
				});
				uni.onSocketMessage(function (res) {
				  console.log('收到服务器内容：' + decode(res.data));
				});
				
				uni.onSocketClose(function (res) {
				  console.log('WebSocket 已关闭！');
				});

	    }
}
	}
</script>

<style>
	.box{
		padding: 0 100upx;
		position: relative;
	
	}
	.logo{
		width: 100%;
		width: 100%;
		height: 310upx;
	}
	.title{
		position: absolute;
		top: 0;
		line-height: 360upx;
		font-size: 68upx;
		color: #fff;
		text-align: center;
		width: 100%;
		margin-left: -100upx;
	}
	.form{
		margin-top: 300upx;
	}
	.input{
		background: #e2f5fc;
		margin-top: 30upx;
		border-radius: 100upx;
		padding: 20upx 40upx;
		font-size: 36upx;
	}
	.input-placeholder, .input{
		color: #94afce;
	}
	.label{
		padding: 60upx 0;
		text-align: center;
		font-size: 30upx;
		color: #a7b6d0;
	}
	.btn{
		background: #ff65a3;
		color: #fff;
		border: 0;
		border-radius: 100upx;
		font-size: 36upx;
	}
	.btn:after{
		border: 0;
	}
	/*按钮点击效果*/
	.btn.button-hover{
		transform: translate(1upx, 1upx);
	}
</style>
